import { h } from 'vue';
import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';
import { cacheApi } from '@/api/sys/common';
import { Tag } from 'ant-design-vue';
export const columns: BasicColumn[] = [
  {
    title: '标题',
    align: 'center',
    dataIndex: 'title',
  },
  {
    title: '摘要',
    align: 'center',
    dataIndex: 'msgAbstract',
  },
  // {
  //   title: '开始时间',
  //   align: 'center',
  //   dataIndex: 'startTime',
  // },
  // {
  //   title: '结束时间',
  //   align: 'center',
  //   dataIndex: 'endTime',
  // },
  {
    title: '发布人',
    align: 'center',
    dataIndex: 'sender',
  },
  {
    title: '优先级',
    align: 'center',
    dataIndex: 'priorityStr',
  },
  {
    title: '消息类型',
    align: 'center',
    dataIndex: 'msgCategoryStr',
  },
  {
    title: '通告对象',
    align: 'center',
    dataIndex: 'msgTypeStr',
  },

  {
    title: '发布状态',
    align: 'center',
    dataIndex: 'sendStatusStr',
    customRender: ({ text, record }) => {
      let color = 'default';
      if (record.sendStatus == 1) {
        color = 'success';
      }
      if (record.sendStatus == 2) {
        color = 'error';
      }
      return h(Tag, { color }, text);
    },
  },
  {
    title: '发布时间',
    align: 'center',
    dataIndex: 'sendTime',
  },
  {
    title: '撤销时间',
    align: 'center',
    dataIndex: 'cancelTime',
  },

  {
    title: '创建时间',
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: '修改用户',
    align: 'center',
    dataIndex: 'updateUser',
  },
  {
    title: '创建用户',
    align: 'center',
    dataIndex: 'createUser',
  },
  {
    title: '修改时间',
    align: 'center',
    dataIndex: 'updateTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '标题',
    field: 'title',
    component: 'Input',
  },
  {
    label: '创建时间',
    field: 'createTime',
    component: 'RangePicker',
  },
  {
    label: '发布时间',
    field: 'sendTime',
    component: 'RangePicker',
  },
  {
    label: '发布时间',
    field: 'sendTime',
    component: 'RangePicker',
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show: false,
  },
  {
    field: 'title',
    label: '标题',
    component: 'Input',
    required: true,
    colProps: {
      span: 12,
    },
  },
  {
    field: 'msgAbstract',
    label: '摘要',
    component: 'InputTextArea',
    required: true,
    colProps: {
      span: 24,
    },
  },
  {
    field: 'priority',
    label: '优先级',
    required: true,
    component: 'ApiRadioGroup',
    defaultValue: 'general',
    componentProps: {
      dictCode: 'notice_level',
    },
    colProps: {
      span: 24,
    },
  },
  {
    field: 'msgCategory',
    label: '消息类型',
    component: 'ApiRadioGroup',
    defaultValue: 'tz',
    componentProps: {
      dictCode: 'notice_type',
    },
    required: true,
    colProps: {
      span: 24,
    },
  },
  {
    field: 'msgType',
    label: '通告对象类型',
    component: 'ApiRadioGroup',
    required: true,
    defaultValue: 'toAll',
    componentProps: {
      dictCode: 'notice_modify_type',
    },
    colProps: {
      span: 24,
    },
  },
  {
    field: 'userIds',
    label: '指定用户',
    component: 'ApiSelect',
    required: true,
    ifShow: ({ values }) => values.msgType === 'toUser',
    colProps: {
      span: 24,
    },
    componentProps: {
      mode: 'multiple',
      api: cacheApi,
      params: { keyCode: 'user' },
    },
  },
  {
    field: 'roleIds',
    label: '指定角色',
    component: 'ApiSelect',
    required: true,
    ifShow: ({ values }) => values.msgType === 'toRole',
    colProps: {
      span: 24,
    },
    componentProps: {
      mode: 'multiple',
      api: cacheApi,
      params: { keyCode: 'role' },
    },
  },
  {
    field: 'msgContent',
    label: '',
    component: 'RichText',
    required: true,
    defaultValue: '',
    colProps: {
      span: 24,
    },
  },
];